package com.sdy.dao.mysql.provider;

import com.sdy.po.Notic;
import com.sdy.po.User;

import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

/**
 * 自定义MyBatis语句
 */
public class NoticProvider {

    /**
     * 批量插入
     * @param map
     * @return
     */
    public String batchInsert(Map map) {
        List<User> receiveUserList = (List<User>) map.get("receiveUserList");
        StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.append("INSERT INTO po_notic (companyId,title,info,data,noticState,readState,Time,parmId,userId) VALUES ");

        MessageFormat mf = new MessageFormat(
                "(#'{'receiveUserList[{0}].companyId}," +
                        "#'{'notic.title}," +
                        "#'{'notic.info}," +
                        "#'{'notic.data}," +
                        "#'{'notic.noticState}," +
                        "#'{'notic.readState}," +
                        "#'{'notic.Time}," +
                        "#'{'notic.parmId}," +
                        "#'{'receiveUserList[{0}].id})");

        for (int i = 0; i < receiveUserList.size(); i++) {
            stringBuilder.append(mf.format(new Object[] {i}));
            if (i < receiveUserList.size() - 1)
                stringBuilder.append(",");
        }
        return stringBuilder.toString();
    }
}
